﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using TierService;
using OrderMgr.SysSetting;
using TierApplication;

namespace OrderMgr.Rpt
{
    public partial class frmRptStock : TierService.frmTemplate
    {
        public string _OrderID;

        public frmRptStock()
        {
            InitializeComponent();
            this.Text = "库存汇总";
        }

        private void initForm()
        {
            Utility.DataToLookupComboxEx(txtDepotID, C_DMB.GetListByType(C_DMB.DType.DepotType.ToString()), "CodeID", "CodeName");
            Utility.DataToLookupComboxEx(txtProductType, C_DMB.GetListByType(C_DMB.DType.ProductType.ToString()), "CodeID", "CodeName");
            this.txtOrderDateStart.DateTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-01"));
            this.txtOrderDateEnd.DateTime = DateTime.Now.Date;
            this.ckbDepotID.Checked = true;
            this.txtDepotID.EditValue = "1";
        }

        private void frmRptStock_Load(object sender, EventArgs e)
        {
            initForm();

        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            string sStartDate = txtOrderDateStart.DateTime.ToString("yyyyMMdd");
            string sEndDate = txtOrderDateEnd.DateTime.ToString("yyyyMMdd");
            string sProductType = "";
            string sDepotID = (string)txtDepotID.EditValue;
            string sProductName = "";
            if (ckbProductType.Checked)
            {
                sProductType = (string)txtProductType.EditValue;
            }
            else
            { sProductType = ""; }

            if (ckbProductName.Checked)
            {
                sProductName = txtProductName.Text;
            }
            else
            {
                sProductName = "";
            }

            DataSet dsRptStock = T_Product.GetRptStock(sStartDate, sEndDate, sProductType, sDepotID,sProductName);
            gcOrder.DataSource = dsRptStock.Tables[0];
        }

        private void btnExportExcel_Click(object sender, EventArgs e)
        {
            TierService.Utility.DataExportToExcel(gvOrder, "订单信息");
        }



        private void gvOrder_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
        {
            e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
            if (e.Info.IsRowIndicator)
            {
                if (e.RowHandle >= 0)
                {
                    e.Info.DisplayText = (e.RowHandle + 1).ToString();
                }
                else if (e.RowHandle < 0 && e.RowHandle > -1000)
                {
                    e.Info.Appearance.BackColor = System.Drawing.Color.AntiqueWhite;
                    e.Info.DisplayText = "G" + e.RowHandle.ToString();
                }
            }
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            if (gvOrder.RowCount < 1) return;
            DataRow dr = gvOrder.GetDataRow(gvOrder.FocusedRowHandle);
            string sID = dr["ProductID"].ToString();

            frmRptStockDetail fDetail = new frmRptStockDetail();
            fDetail._ProductID = sID;
            fDetail._DepotID = (string)txtDepotID.EditValue;
            fDetail._StartDate = txtOrderDateStart.DateTime;
            fDetail._EndDate = txtOrderDateEnd.DateTime;
            fDetail.ShowDialog();

        }



        private void gvOrder_DoubleClick(object sender, EventArgs e)
        {
            if (gFuncType == Utility.FuncType.Select)
            {
                if (gvOrder.RowCount < 1) return;
                DataRow dr = gvOrder.GetDataRow(gvOrder.FocusedRowHandle);
                _OrderID = dr["OrderID"].ToString();
                DialogResult = System.Windows.Forms.DialogResult.OK;

            }
            else { btnQuery_Click(null, null); }

        }




        private void btnClose_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void gvOrder_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
        {
            //if (e.RowHandle >= 0)
            //{
            //    DataRow dr = gvOrder.GetDataRow(e.RowHandle);
            //    string OrderActQuantity,StockSumCount;
            //    OrderActQuantity = dr["OrderActQuantity"].ToString();
            //    StockSumCount = dr["StockSumCount"].ToString();
            //    if (OrderActQuantity != StockSumCount)
            //    {
            //        e.Appearance.ForeColor = Color.Red;
            //    }

            //}
        }








    }
}